import Vue from 'vue'
import VueRouter from 'vue-router'
import MailboxLayout from "@/views/Mailbox/MailboxLayout.vue";
import MailboxSidebar from "@/views/Mailbox/MailboxSidebar.vue";
import InboxHeader from "@/components/Header/InboxHeader.vue";
import DraftHeader from "@/components/Header/DraftHeader.vue";
import MailDetail from "@/components/Mailbox/MailDetail.vue";
import MailboxHome from "@/views/Mailbox/MailboxHome.vue";
import MailboxList from "@/views/Mailbox/MailboxList.vue";
import ContactList from "@/views/Contact/ContactList.vue";
import MailWrite from "@/components/Mailbox/MailWrite.vue";
import DraftDetail from "@/components/Mailbox/DraftDetail.vue";
import ReplyDetail from "@/components/Mailbox/ReplyDetail.vue";
import SentHeader from "@/components/Header/SentHeader.vue";
import DeletedHeader from "@/components/Header/DeletedHeader.vue";
import SpamHeader from "@/components/Header/SpamHeader.vue";
import StarHeader from "@/components/Header/StarHeader.vue";
import MailboxHeader from "@/components/Header/MailboxHeader.vue";
import SearchHeader from "@/components/Header/SearchHeader.vue";
import UserLayout from "@/views/User/UserLayout.vue";
import UserList from "@/views/User/UserList.vue";
import UserHeader from "@/components/User/UserHeader.vue";
import UserSidebar from "@/views/User/UserSidebar.vue";
import FindPass from "@/components/Index/FindPass.vue";



import AppLayout from "@/views/AppLayout.vue";
import UserLogin from "@/views/Index/UserLogin.vue";
import UserRegister from "@/views/Index/UserRegister.vue";
import LogList from "@/views/Log/LogList.vue";
import MailList from "@/views/Mail/MailList.vue";
import RePassWord from "@/views/Index/RePassWord.vue";
import UserCenter from "@/views/Index/UserCenter.vue";


Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'UserLogin',
        component: UserLogin
    },
    {
        path: '/UserRegister',
        name: 'UserRegister',
        component: UserRegister
    },

    {
        path: '/Home',
        name: 'AppLayout',
        component: AppLayout,
        // 定义在children的路由path不用加斜杠
        children: [
            // 个人中心
            {path: "UserCenter", name: 'UserCenter', component: UserCenter},
            // 写邮件
            {path: "MailWrite", name: 'MailWrite', component: MailWrite},
            // 接收邮箱
            {path: "MailList", name: "MailList", component: MailList},
            // 通讯录
            {path: 'ContactList', name: 'ContactList', component: ContactList},
            // 日志管理
            {path: 'LogList', name: 'LogList', component: LogList},
            // 系统管理
            // 用户管理
            {
                path: 'UserList', name: 'UserList', component: UserList,
                meta: {
                    requireAuth: true, // 需要用户权限
                    roles: ['admin'] // 受访问限制的角色
                }
            },
            // 草稿箱
            // 修改密码。
            {path: "RePassWord", name: "RePassWord", component: RePassWord},
        ],
    },

















    {
        path: '/findPass',
        name: 'FindPass',
        component: FindPass
    },
    {
        path: '/user',
        name: 'UserLayout',
        component: UserLayout,
        children: [
            {
                path: '',
                name: 'UserSidebar',
                component: UserSidebar
            },
            {
                path: 'userList',
                name: 'UserList',
                component: UserList
            },
            {
                path: 'userHeader',
                name: 'UserHeader',
                component: UserHeader
            },
        ]

    },


    {

        path: '/home',
        name: 'MailboxLayout',
        component: MailboxLayout,
        children: [
            {
                path: '',
                name: 'MailboxHome',
                component: MailboxHome
            },

            {
                path: 'contactList',
                name: 'ContactList',
                component: ContactList
            },
            {
                path: 'mailWrite',
                name: 'MailWrite',
                component: MailWrite
            },
            {
                path: 'mailboxList/:folderId',
                name: 'MailboxList',
                component: MailboxList,
            },
            {
                path: 'mailboxList/7',
                name: 'MailboxList',
                component: MailboxList,
            },

            {
                path: 'mailDetail/:id',
                name: 'MailDetail',
                component: MailDetail,
            },
            {
                path: 'draftDetail/:id',
                name: 'DraftDetail',
                component: DraftDetail,
            },
            {
                path: 'replyDetail/:id',
                name: 'ReplyDetail',
                component: ReplyDetail,
            },


        ]
    },
    {
        path: '/',
        name: 'MailboxHeader',
        component: MailboxHeader
    },
    {
        path: '/contactList',
        name: 'ContactList',
        component: ContactList
    },
    {
        path: '/mailboxHome',
        name: 'MailboxHome',
        component: MailboxHome
    },
    {
        path: '/mailboxSidebar',
        name: 'MailboxSidebar',
        component: MailboxSidebar
    },
    {
        path: '/mailboxHeader',
        name: 'MailboxHeader',
        component: MailboxHeader
    },
    {
        path: '/searchHeader',
        name: 'SearchHeader',
        component: SearchHeader
    },


    // {
    //     path: '/mailboxList/:folderId',
    //     name: 'MailboxList',
    //     component: MailboxList,
    // },

    // {
    //     path: '/mailDetail/:id',
    //     name: 'MailDetail',
    //     component: MailDetail,
    // },
    {
        path: '/inboxHeader',
        name: 'InboxHeader',
        component: InboxHeader
    },
    {
        path: '/draftHeader',
        name: 'DraftHeader',
        component: DraftHeader
    },
    {
        path: '/sentHeader',
        name: 'SentHeader',
        component: SentHeader
    },
    {
        path: '/deletedHeader',
        name: 'DeletedHeader',
        component: DeletedHeader
    },
    {
        path: '/spamHeader',
        name: 'SpamHeader',
        component: SpamHeader
    },
    {
        path: '/starHeader',
        name: 'StarHeader',
        component: StarHeader
    },


]
const router = new VueRouter({
    routes
})

const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch(err => err)
}

export default router
